package net.dgg.iboss.sc.backservice.task.quartz;/**
 * Created by Administrator on 2018/5/25.
 */

import net.dgg.iboss.sc.backservice.task.service.CommonService;
import net.dgg.iboss.sc.backservice.task.service.ProductOrderService;
import net.dgg.iboss.sc.backservice.task.service.ZzInProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;


/**
 * <p>@Title 生产定时器任务</p>
 * <p>@Description 办理中相关</p>
 * <p>@Version 1.0.0 版本号</p>
 * <p>@author maoquanyi</p>
 * <p>@date 2018年08月17日</p>
 * <p>Copyright © dgg group.All Rights Reserved. 版权信息</p>
 */
@Component
public class ProductOrderJob {
    private Logger logger = LoggerFactory.getLogger(this.getClass());


    //新的
    @Autowired
    private ProductOrderService productOrderService;
    @Autowired
    private ZzInProcessService zzInProcessService;
    @Autowired
    private CommonService commonService;

    /**
    * <p>@Description 更新分配超期状态</p>
    * <p>@author mqy</p>
    * <p>@Time 2018/9/5 0005 16:15 创建时间</p>
    * <p>@return</p>
    */
    //@Scheduled(cron = "0 0 0/1 * * ? ")
    public void updateAllotTimeStatusAndSendMsg() {
        try {
            this.productOrderService.updateAllotTimeStatusAndSendMsg();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新生产主订单分配超期时出现异常！");
        }
    }
    /**
    * <p>@Description 更新接收超期状态并发送消息</p>
    * <p>@author mqy</p>
    * <p>@Time 2018/9/5 0005 16:42 创建时间</p>
    * <p>@return</p>
    */
    //@Scheduled(cron = "0 0 0/50 * * ? ")
    public void updateReceiveTimeStatus() {
        try {
            this.productOrderService.updateReceiveTimeStatus();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新生产子订单接收超期时出现异常！");
        }
    }
    /**
    * <p>@Description 更新订单超期状态</p>
    * <p>@author mqy</p>
    * <p>@Time 2018/9/5 0005 16:49 创建时间</p>
    * <p>@return</p>
     */
    //@Scheduled(cron = "0 0 0/1 * * ? ")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    @Scheduled(cron = "0 0 10 ? * 1,5")
    public void updateOrderTimeStatus() {
        try {
            this.productOrderService.updateOrderTimeStatus();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新生产子订单订单超期时出现异常！");
        }
    }
    /**
    * <p>@Description 更新预计开启时间超期状态</p>
    * <p>@author mqy</p>
    * <p>@Time 2018/9/5 0005 16:59 创建时间</p>
    * <p>@return</p>
     */
    //@Scheduled(cron = "0 0 0/1 * * ? ")
    @Scheduled(cron = "0 0 10 * * ? ")
    public void updateExpectOpenTimeStatus() {
        try {
            this.productOrderService.updateExpectOpenTimeStatus();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新预计开启时间超期时出现异常！");
        }
    }
    /**
     * 更新中止订单,默认暂停180的订单或者办理中节点180天未更新
     */
    @Scheduled(cron = "0 49 16 * * ? ")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    public void updateStopOrder() {
        try {
            this.productOrderService.updateStopOrder();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新中止订单时出现异常！");
        }
    }
    /**
     *
     */
    @Scheduled(cron = "0 0 10,15 * * ?")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    public void zsOrderOverdue() {
        try {
            if(commonService.isWorkDay(new Date())) {
                productOrderService.zsOrderOverdueAlert();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("证书入库即将超期提醒出现异常！");
        }
    }
    /**
     *
     */
    @Scheduled(cron = "0 0 9 * * ?")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    public void zsOrderOver() {
        try {
            if(commonService.isWorkDay(new Date())) {
                productOrderService.zsOrderOverAlert();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("证书入库超期提醒出现异常！");
        }
    }
    /**
     * <p>@Description 更新合同超期状态</p>
     */
    //@Scheduled(cron = "0 30 14 * * ? ")
     @Scheduled(cron = "0 0 10 ? * 1,5")
    //@Scheduled(cron = "0 0/1 * * * ? ")
    public void updateContractTimeStatus() {
        try {
            this.productOrderService.updateContractTimeStatus();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新合同超期状态时出现异常！");
        }
    }
    /**
     * <p>@Description 节点预警</p>
     */
    @Scheduled(cron = "0 0 10,15 * * ? ")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    public void nodeAlert() {
        try {
            if(commonService.isWorkDay(new Date())) {
                this.productOrderService.nodeAlert();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("节点预警时出现异常！");
        }
    }
    /**
     * <p>@Description 节点超期提醒</p>
     */
    @Scheduled(cron = "0 0 9 * * ? ")
    //@Scheduled(cron = "0 0/1 * * * ? ")
    public void nodeOutTimeAlert() {
        try {
            if(commonService.isWorkDay(new Date())) {
                zzInProcessService.nodeTimeOutAlert();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("节点超期提醒时出现异常！");
        }
    }
    /**
     * <p>@Description 节点超期扣罚</p>
     */
    @Scheduled(cron = "0 0 15 * * ? ")
    //@Scheduled(cron = "0 0/1 * * * ? ")
    public void nodeOutTimePunish() {
        try {
            if(commonService.isWorkDay(new Date())) {
                zzInProcessService.nodeTimeOutPunish();
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("节点超期扣罚时出现异常！");
        }
    }
    /**
     * <p>@Description 订单预警</p>
     */
    //@Scheduled(cron = "0 30 14 * * ? ")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    //0 00 9,12 ? * MON ,FIR
    @Scheduled(cron = "0 0 10 ? * 1,5")
    //@Scheduled(cron = "0 0/1 * * * ? ")
    public void orderAlert() {
        try {
            this.productOrderService.orderAlert();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("订单预警时出现异常！");
        }
    }
    /**
     * <p>@Description 合同预警</p>
     */
    //@Scheduled(cron = "0 25 17 * * ? ")
    //@Scheduled(cron = "0 0/50 * * * ? ")
    @Scheduled(cron = "0 0 10 ? * 1,5")
    //@Scheduled(cron = "0 0/1 * * * ? ")
    public void contractAlert() {
        try {
            this.productOrderService.contractAlert();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("合同预警时出现异常！");
        }
    }

    public void certificateMatchFailedSendMsg(){
        try {
            this.productOrderService.certificateMatchFailedSendMsg();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("证书匹配失败消息通知出现异常！");
        }
    }
}
